﻿using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.Driver.DriverExamine;
using BCService.TMS.Driver.DriverExamine;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.Driver
{
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class DriverExamineMarksController : ManagementBaseController
    {
        private readonly IDriverExamineMarkService driverExamineMarkService;

        public DriverExamineMarksController(IDriverExamineMarkService driverExamineMarkService)
        {
            this.driverExamineMarkService = driverExamineMarkService;
        }
        /// <summary>
        /// 获取考试成绩列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="size">页数</param>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<DriverExamineMarkDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult GetDriverExamineMarks([FromQuery(Name = "index")] int index = 1, [FromQuery(Name = "size")] int size = 10)
        {
            return Ok(driverExamineMarkService.GetByPaging(index, size));
        }

        /// <summary>
        /// 获取指定的考试成绩
        /// </summary>
        /// <param name="examineMarkId"></param>
        /// <returns></returns>
        [HttpGet("{examine_mark_id}")]
        [ProducesResponseType(typeof(DriverExamineMarkDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult GetDriverExamineMarkById([FromRoute(Name = "examine_mark_id")] long examineMarkId)
        {
            return Ok(driverExamineMarkService.GetById(examineMarkId));
        }

        /// <summary>
        /// 新增司机考试成绩
        /// </summary>
        /// <param name="driverExamineMark"></param>
        /// <returns></returns>
        [HttpPost]
        [Log("新增司机考试成绩")]
        [ProducesResponseType(typeof(DriverExamineMarkDto), 201)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Add([FromBody] DriverExamineMarkRequestDto driverExamineMark)
        {
            var id = driverExamineMarkService.Add(driverExamineMark);
            var result = driverExamineMarkService.GetById(id);
            return Created(string.Format("/api/v1/sim/DriverExamineMarks/{0}", id), result);
        }

        /// <summary>
        /// 更新指定的成绩单信息
        /// </summary>
        /// <param name="examineMarkId">成绩单编号</param>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut("{examine_mark_id}")]
        [Log("更新指定的成绩单信息")]
        [ProducesResponseType(typeof(DriverExamineMarkDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromRoute(Name = "examine_mark_id")] long examineMarkId, [FromBody] DriverExamineMarkRequestDto dto)
        {
            return Ok(driverExamineMarkService.Update(examineMarkId, dto));
        }

    }
}
